package com.xgkj.diyiketang.task;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xgkj.diyiketang.data.GifInfo;
import com.xgkj.diyiketang.http.CouponHttpRequest;
import com.xgkj.diyiketang.http.CouponHttpResponse;
import com.xgkj.diyiketang.http.engine.CouponHttpBaseTask;
import com.xgkj.diyiketang.http.engine.TaskResultCode;

/**
 * Created by windo on 16/9/1.
 */
public class SongLiwuTask extends CouponHttpBaseTask {
    private String vid;
    private String giftId;
    private int lianjiCount;
    public SongLiwuTask(String vid,String giftId,int comboCount) {
        super();
        this.vid = vid;
        this.giftId  = giftId;
        lianjiCount = comboCount;

    }

    @Override
    protected void processResponseData(CouponHttpResponse response) {
        JSONObject jsonObject = response.getBody();
//        String coinBalance = jsonObject.getString("coinBalance");
        GifInfo info = JSON.parseObject(jsonObject.toString(),GifInfo.class);
        notifyTaskCompleted(TaskResultCode.SUCCESS,info);
    }

    @Override
    protected void prepareRequest() {
        super.prepareRequest();
        if (mPhase == TASK_PHASE_INIT){
            CouponHttpRequest request = new CouponHttpRequest();
            request.setApiNo(ApiNo.ZHIBO_SONGLIWU);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("vid",vid);
            jsonObject.put("giftId",giftId);
            jsonObject.put("comboCount",lianjiCount);
            request.setData(jsonObject.toString());
            addRequest(request);
        }
    }
}
